package cn.tools.jwt.config;


import cn.tools.jwt.client.entiry.JwtHeadConfig;
import cn.tools.jwt.client.utils.JwtCreateToken;
import cn.tools.jwt.server.utils.JwtTokenDecode;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: e
 * @date: 2021/12/9
 * @description:
 * yml 配置推荐
 * auth-jwt:
 *   head:
 *     alg: HS256   #配置加密算法，HS256就无需配置公钥私钥路径，如果是RS256则配置路径，并先调用生成方法生成一次
 *     typ: JWT
 *   key: keno
 *   prikey: prikey
 *   pubkey: pubkey
 *
 * 建议先生成出公钥和私钥然后放置到resource下，这里直接写名字，他就默认去这下面找
 */

@EnableConfigurationProperties(JwtHeadConfig.class)
@Configuration
public class JwtAutoConfiguration {
    private JwtHeadConfig jwtHeadConfig;

    public JwtAutoConfiguration(JwtHeadConfig jwtHeadConfig){
        this.jwtHeadConfig = jwtHeadConfig;
    }


    @Bean
    @ConditionalOnMissingBean
    public JwtCreateToken jwtTokenServerUtils(){
        return new JwtCreateToken(jwtHeadConfig);
    }


    @Bean
    @ConditionalOnMissingBean
    public JwtTokenDecode jwtTokenDecode(){
        return new JwtTokenDecode(jwtHeadConfig);
    }


}
